JavaScript Hacks: Tips, Tricks, and Techniques for JavaScript by William Clarkson

JavaScript Hacks: Tips, Tricks, and Techniques for JavaScript by William Clarkson

Author:William Clarkson [Clarkson, William]
Language: eng
Format: azw3
Published: 2018-10-13T16:00:00+00:00


Get Max or Min values

Use the built-in math functions of JavaScript to get the maximum or minimum number in an array

var numbers = [3, 3354, 143, -245, 118, 400, 122222, -80011];

var maxInNumbers = Math.max.apply(Math, numbers);

var minInNumbers = Math.min.apply(Math, numbers);

//

//

console.log("max", maxInNumbers);

console.log("min=" + minInNumbers);

Output

122222

-80011

Random In Range

This function will return a random whole number between the two numbers that are passed to it.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.